#include "FileWriter.h"

FileWriter1::FileWriter1(QString filePath, QByteArray data, QFile::OpenModeFlag openModeFlag)
{
	this->filePath = filePath;
	this->data = data;
	this->openModeFlag = openModeFlag;
}

FileWriter1::~FileWriter1()
{
}

void FileWriter1::run()
{
	QFile file(filePath);
	if (file.open(openModeFlag))
	{
		int size=file.write(data);
		file.flush();
		file.close();
		emit signal_writeFileSuccessful(filePath);
	}
	else
	{
		emit signal_writeFileFailed(filePath);
	}
	emit signal_runningFinished(filePath);
}

FileWriter::FileWriter(QObject* parent) :QObject(parent)
{
}

FileWriter::~FileWriter()
{
}

void FileWriter::slot_continueRun(QString filePath)
{
	locker.lock();
	QList<FileWriter1*> temp = missionQueue.take(filePath);
	temp.removeFirst();
	if (!temp.isEmpty())
	{
		missionQueue.insert(filePath,temp);
		qThreadPool->start(temp.first());
	}
	locker.unlock();
}

QThreadPool* FileWriter::getQThreadPool()
{
	return qThreadPool;
}
void FileWriter::setQThreadPool(QThreadPool* qThreadPool)
{
	this->qThreadPool = qThreadPool;
}

